<?php
namespace app\admin\controller;

use think\Config;
use think\Session;
class Sign extends Base
{

    public function __construct()
    {
        parent::__construct();
		$this->User = D('User');
    }

    public function in()
    {
        $username = I('post.username');
        $passwd = I('post.passwd');


        if(empty($username) || empty($passwd)){

            return $this->view->fetch();
        }

		//验证码
		   if(check_verify($_POST['verify']) === false){
             return $this->error('验证码错误');
            }else{
				//执行
				$userModel = D('admin/User');
				$result = $userModel->check($username, $passwd);
				if($result){
					$where['username']=$username;
					$data['lasttime']=time();
					$result_info = $this->User->where($where)->save($data);
					$user_info =$this->User->where($where)->find();
					 if($result_info){
						manage_log_success();
						session('user',1);
						session('username',$username);
						session('id',$result['id']);
						session('lastAct', time());	
					}
					$this->redirect('Index/index');
				  }
				$this->view->assign('err',1);
				return $this->view->fetch();
				//执行 END
			}



    }




    public function out()
    {
	    manage_log_success();
        session('user', null);
        return $this->view->fetch('sign/in');
    }
}
